using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using System.Xml;

namespace YB.EnterpriseLibrary.XSLTManager.Configuration
{
    public class XSLTManagerData : NamedConfigurationElement
    {
        public XSLTManagerData() : base()
        {             
        }

        public XSLTManagerData(string name)
            : base(name)
		{
		}

        private const string urlProperty = "url";
        [ConfigurationProperty(urlProperty, IsRequired = true)]
        public string Url
        {
            get { return (string)this[urlProperty]; }
            set { this[urlProperty] = value; }
        }

        private const string debugProperty = "debug";
        [ConfigurationProperty(debugProperty, IsRequired = true)]
        public bool Debug
        {
            get { return (bool)this[debugProperty]; }
            set { this[debugProperty] = value; }
        }

        private const string enableDocumentFunctionProperty = "enableDocumentFunction";
        [ConfigurationProperty(enableDocumentFunctionProperty, IsRequired = true)]
        public bool EnableDocumentFunction
        {
            get { return (bool)this[enableDocumentFunctionProperty]; }
            set { this[enableDocumentFunctionProperty] = value; }
        }

        private const string enableScriptProperty = "enableScript";
        [ConfigurationProperty(enableScriptProperty, IsRequired = true)]
        public bool EnableScript
        {
            get { return (bool)this[enableScriptProperty]; }
            set { this[enableScriptProperty] = value; }
        }

        private const string mimeTypeProperty = "mimeType";
        [ConfigurationProperty(mimeTypeProperty, IsRequired = true)]
        public string MimeType
        {
            get { return (string)this[mimeTypeProperty]; }
            set { this[mimeTypeProperty] = value; }
        }
    }

    public class XSLTManagerDataRetriever : IConfigurationNameMapper
    {
        public string MapName(string name, IConfigurationSource configurationSource)
        {
            if (name == null)
            {
                XSLTManagerConfigurationView view = new XSLTManagerConfigurationView(configurationSource);
                return view.DefaultXSLTManager;
            }

            return name;
        }
    }

}
